package collector

import (
	"encoding/json"
	"io/ioutil"

	log "github.com/sirupsen/logrus"
)

func LoadPwdFile(passwordFile string) (map[string]UserInfo, error) {
	res := make(map[string]UserInfo)

	bytes, err := ioutil.ReadFile(passwordFile)
	if err != nil {
		log.Warningln("load password file failed:", err)
		return nil, err
	}

	err = json.Unmarshal(bytes, &res)
	if err != nil {
		log.Warningln("password file format error:", err)
		return nil, err
	}

	return res, nil
}
